<template>
	<view>
		<metabs v-model="tabIndex" :tabs="tabs" :height='92' ></metabs>
		<swiper :style="{height: height}" :current="tabIndex" @change="swiperChange"  :borderNone="false">
			<swiper-item v-for="(tab,i) in tabs" :key="i">
				<mescroll-item ref="mescrollItem" :i="i" :index="tabIndex" :tabs="tabs" :height="height"></mescroll-item>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import metabs from '@/components/me-tabs/me-tabs.vue'
	import MescrollItem from "./components/mescroll-swiper-item.vue";
	import * as userApi from '@/api/user'
	export default{
		data(){
			return{
				height: "", // 需要固定swiper的高度
				tabs: [],
				tabIndex: 0 // 当前tab的下标
			}
		},
		components:{
			metabs,
			MescrollItem,
		},
		onLoad(options) {
			this.getWithType(options)
			this.getIndexType(options)
			
			// 需要固定swiper的高度 (需减去悬浮tabs的高度64rpx)
			this.height = uni.getSystemInfoSync().windowHeight - uni.upx2px(64) + 'px'
		},
		onShow() {
			if(this.tabIndex === 2){
				this.$nextTick(function() {
					let bankListOne = uni.getStorageSync("bankListOne")
					if(bankListOne){
						let _this = this
						// uni.removeStorageSync("bankListOne")
						_this.$refs.mescrollItem[this.tabIndex].bankName(bankListOne.bank_name)
					}
				})
			}
			// 返回刷新: https://www.mescroll.com/uni.html#note 第二点
			// if(this.canReset){
			// 	let curMescroll = this.getMescroll(this.tabIndex)
			// 	curMescroll && curMescroll.resetUpScroll()
			// }
			// this.canReset = true
		},
		methods: {
			
			getWithType(options){
				let token = uni.getStorageSync("AccessToken")
				userApi.getWithdrawType({
					wxapp_id: this.$wxapp_id,
					token: token,
				}).then(res=>{
					let type_tixian = res.data
					if(type_tixian.aliPay === 1){
							let blec = 0
							// #ifndef MP-WEIXIN
							blec = 1
							// #endif
							// #ifdef MP-WEIXIN
							if(uni.getStorageSync("Wxstatus").status_wx === 0){
								blec = 0
							}else{
								blec = 1
							}
							// #endif
							if(blec === 1){
								this.tabs.push({"name":"支付宝",'tage':1})
							}
					}
					if(type_tixian.wxPay === 1){
						let blec_wx = 1
						if(blec_wx === 1){
							this.tabs.push({"name":"微信",'tage':3})
						}
					}
					if(type_tixian.bankPay === 1){
						this.tabs.push({"name":"银行卡",'tage':2})
					}
					this.getIndexType(options)
				}).catch(()=>{
				})
			},
			getIndexType(options){
				if(options){
					for(let i=0;i<this.tabs.length;i++){
						if(Number(options.tage) === this.tabs[i].tage){
							let dict = {detail:{current:i}}
							this.swiperChange(dict)
							break
						}
					}
				}
			},
			// 轮播菜单
			swiperChange(e){
				this.tabIndex = e.detail.current
			},
		}
	}
</script>

<style lang="scss">
	page{
		// background-color: #FAFAFA;
    background-color: #F1F6F9;
	}
</style>